/*
** collatz.c
** 
** Made by (seakage2h)
** Login   <seakage2h@seakage2h-ubuntu>
** 
** Started on  Wed Mar 11 21:53:17 2009 seakage2h
** Last update Sun May 12 01:17:25 2002 Speed Blue
*/

#include <stdio.h>
#define MAXNUM 1000000
#define DNUM 1000
#define PERLINE 9
int main()
{
    int d[MAXNUM];
    int i, tmpd, tmpi;

    /* some initial values */
    d[1] = 3, d[2] = 3, d[3] = 8, d[4] = 3, d[5] = 6, d[6] = 9, d[7] = 17;

    for(i = 8; i < MAXNUM; d[i++] == 0);
    
    for(i = 8; i < DNUM; i++){
        tmpd = 0;
        tmpi = i;
        while(!d[tmpi]){
            if (tmpi & 1)
                tmpi = tmpi * 3 + 1;
            else tmpi >>= 1;
            tmpd++;
        }
        d[i] = tmpd + d[tmpi];
    }

    for(i = 1; i < DNUM; i += PERLINE){
        printf("Number: ");
        for(tmpi = i; tmpi < i + PERLINE; tmpi++)
            printf("%d\t", tmpi);
        putchar('\n');
        printf("Dist:   ");
        for(tmpi = i; tmpi < i + PERLINE; tmpi++)
            printf("%d\t", d[tmpi]);
        putchar('\n');
        putchar('\n');
    }
    
    return 0;
}

